home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / packet / p_aa4re / bb212src / bbconv.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-03-07  |  12.0 KB  |  355 lines

  1. (*===========================================================================*)
  2. (* Converse between tasks                                                    *)
  3. (*                                                                           *)
  4. (*   Copyright 1988, 1989, 1990, 1991, 1992 by H. Roy Engehausen.  All       *)
  5. (*   rights reserved.                                                        *)
  6. (*                                                                           *)
  7. (*===========================================================================*)
  8.  
  9. {$O+}
  10.  
  11. UNIT BBCONV;
  12.  
  13. INTERFACE
  14.  
  15. PROCEDURE operator_terminal_task;
  16. PROCEDURE operator_talk_action;
  17. PROCEDURE converse_talk_loop;
  18.  
  19. IMPLEMENTATION
  20.  
  21. USES
  22.   bbconvm,
  23.   bbdummy,
  24.   bbmess,
  25.   bbmisc4,
  26.   bbocmd,
  27.   bbrdata,
  28.   bbsdata,
  29.   bbsess,
  30.   bbstr,
  31.   bbtask,
  32.   bbtime,
  33.   bbucmd,
  34.   bbuf,
  35.   bbwin;
  36.  
  37. PROCEDURE operator_talk_loop; FORWARD;
  38.  
  39. (*===========================================================================*)
  40. (* Operator talk action -- Called by ocmd to accomplish talk for operator    *)
  41. (* The main part of the operator "T" command is in an overlay.  This is the  *)
  42. (* section that cannot be overlayed.                                         *)
  43. (*===========================================================================*)
  44.  
  45. PROCEDURE operator_talk_action;
  46.  
  47.   BEGIN;
  48.  
  49.     operator_talk_loop;
  50.  
  51.     IF active_tcb^.conv_tcb = NIL THEN EXIT;
  52.  
  53.     WITH active_tcb^.conv_tcb^ DO
  54.       BEGIN;
  55.  
  56.         IF tcb_type =  th_opr_terminal THEN
  57.           BEGIN;
  58.             window        := window_connect;
  59.             tcb_ignore_lc := FALSE;
  60.           END;
  61.  
  62.       END;
  63.  
  64.     drop_conv(active_tcb);
  65.  
  66.   END;
  67.  
  68. (*===========================================================================*)
  69. (* Operator talk loop -- This is where operator sits while talking           *)
  70. (*===========================================================================*)
  71.  
  72. PROCEDURE operator_talk_loop;
  73.  
  74.   VAR
  75.     line_from_op : STRING;
  76.  
  77.   BEGIN;
  78.  
  79.     op_busy := TRUE;
  80.  
  81.     (*-----------------------------------------------------------------------*)
  82.     (* This is the talk loop                                                 *)
  83.     (*-----------------------------------------------------------------------*)
  84.  
  85.     WHILE TRUE DO
  86.       WITH active_tcb^ DO
  87.         BEGIN;
  88.  
  89.           (*-----------------------------------------------------------------*)
  90.           (* If other TCB gone away, then bye bye                            *)
  91.           (*-----------------------------------------------------------------*)
  92.  
  93.           IF (conv_tcb = NIL) OR task_is_dead(conv_tcb) THEN EXIT;
  94.  
  95.           (*-----------------------------------------------------------------*)
  96.           (* Get line from operator                                          *)
  97.           (*-----------------------------------------------------------------*)
  98.  
  99.           line_from_op := read_tnc_data_str;
  100.  
  101.           (*-----------------------------------------------------------------*)
  102.           (* If other TCB gone away, then bye bye                            *)
  103.           (*-----------------------------------------------------------------*)
  104.  
  105.           IF (conv_tcb = NIL) OR task_is_dead(conv_tcb) THEN EXIT;
  106.  
  107.           IF NOT op_busy THEN
  108.             BEGIN;
  109.               op_busy := FALSE;
  110.               IF conv_tcb <> NIL THEN
  111.                 conv_tcb^.tcb_opr_talk := FALSE;
  112.               EXIT;
  113.             END;
  114.  
  115.           (*-----------------------------------------------------------------*)
  116.           (* Queue the line                                                  *)
  117.           (*-----------------------------------------------------------------*)
  118.  
  119.           IF line_from_op = '' THEN
  120.             line_from_op := ' ';
  121.  
  122.           (*-----------------------------------------------------------------*)
  123.           (* Either queue or execute the line                                *)
  124.           (*-----------------------------------------------------------------*)
  125.  
  126.           IF (line_from_op[0] > #2)
  127.                                     AND (line_from_op[1] = escape)
  128.                                     AND (line_from_op[2] = escape) THEN
  129.             BEGIN;
  130.               line_from_op := substr(line_from_op, 3, 0);
  131.               execute_opr_command(@line_from_op);
  132.               error_sw := FALSE;
  133.             END
  134.           ELSE
  135.             add_c_string(conv_tcb, @line_from_op, 0);
  136.  
  137.           (*-----------------------------------------------------------------*)
  138.           (* Delete any lines on the receive side.  Note that we don't do    *)
  139.           (* anything with them.  They have already been written to the      *)
  140.           (* screen by the receiving task                                    *)
  141.           (*-----------------------------------------------------------------*)
  142.  
  143.           WHILE c_input <> NIL DO
  144.             BEGIN;
  145.               task_switch;
  146.               del_c_string(active_tcb);
  147.             END;
  148.  
  149.           (*-----------------------------------------------------------------*)
  150.           (* Switch tasks around please                                      *)
  151.           (*-----------------------------------------------------------------*)
  152.  
  153.           task_switch;
  154.  
  155.         END; (*----- Operator talk loop -------------------------------------*)
  156.  
  157.   END;
  158.  
  159. (*===========================================================================*)
  160. (* Operator talk sub-task -- Operator using his keyboard as a terminal       *)
  161. (* and we have to create a sub task for the port                             *)
  162. (*===========================================================================*)
  163.  
  164. PROCEDURE operator_terminal_task;
  165.  
  166.   VAR
  167.     i : BYTE;
  168.  
  169.   BEGIN;
  170.  
  171.     FILLCHAR(active_tcb^.tnc_data, SIZEOF(active_tcb^.tnc_data), 0);
  172.  
  173.     FOR i := 1 TO 10 DO
  174.       task_switch;
  175.  
  176.     converse_talk_loop;
  177.  
  178.     active_tcb^.tcb_ignore_lc := FALSE;
  179.  
  180.     end_session(FALSE);
  181.  
  182.   END;
  183.  
  184. (*===========================================================================*)
  185. (* Converse talk loop -- This is where the user sits when talking            *)
  186. (*===========================================================================*)
  187.  
  188. PROCEDURE converse_talk_loop;
  189.  
  190.   VAR
  191.     delay_to_add : BYTE;
  192.     end_talk     : BOOLEAN;
  193.     i            : BYTE;
  194.     line_to      : STRING;
  195.     modem_line   : BOOLEAN;
  196.     work_scb     : str_m_chain;
  197.  
  198.   LABEL
  199.     leave_loop;
  200.  
  201.   BEGIN;
  202.  
  203.     modem_line := (active_port^.port_type = port_modem)
  204.                                  OR (active_port^.port_type = port_null_modem);
  205.  
  206.     WITH active_tcb^ DO
  207.       BEGIN;
  208.  
  209.         (*-------------------------------------------------------------------*)
  210.         (* If no data then flush things                                      *)
  211.         (*-------------------------------------------------------------------*)
  212.  
  213.         IF c_input = NIL THEN
  214.           send_flush;
  215.  
  216.         (*-------------------------------------------------------------------*)
  217.         (* Initialize for talk loop                                          *)
  218.         (*-------------------------------------------------------------------*)
  219.  
  220.         end_talk := FALSE;
  221.  
  222.         (*-------------------------------------------------------------------*)
  223.         (* Talk loop                                                         *)
  224.         (*-------------------------------------------------------------------*)
  225.  
  226.         WHILE (NOT end_talk) AND (conv_tcb <> NIL) DO
  227.           BEGIN;
  228.  
  229.             (*---------------------------------------------------------------*)
  230.             (* If incoming data then send it.  The local operator can send   *)
  231.             (* command to the user's channel.                                *)
  232.             (*---------------------------------------------------------------*)
  233.  
  234.             IF c_input <> NIL THEN
  235.               BEGIN;
  236.  
  237.                 work_scb := c_input;
  238.  
  239.                 (*-----------------------------------------------------------*)
  240.                 (* Check for incoming command rather than data               *)
  241.                 (*-----------------------------------------------------------*)
  242.  
  243.                 IF (work_scb^.str_m_data.str_data[1] = escape)
  244.                                         AND (work_scb^.str_m_type = 0)
  245.                                         AND (NOT active_tcb^.tcb_binary) THEN
  246.                   BEGIN;
  247.  
  248.                     (*-------------------------------------------------------*)
  249.                     (* Strip the escape plus other stuff                     *)
  250.                     (*-------------------------------------------------------*)
  251.  
  252.                     line_to := COPY(work_scb^.str_m_data.str_data, 2, 255);
  253.                     strip_crlf(line_to);
  254.  
  255.                     (*-------------------------------------------------------*)
  256.                     (* If a second escape is not present then send command to*)
  257.                     (* the TNC else execute the command                      *)
  258.                     (*-------------------------------------------------------*)
  259.  
  260.                     IF (LENGTH(line_to) = 0) OR (line_to[1] <> escape) THEN
  261.                       cmd_tnc(@line_to, TRUE)
  262.                     ELSE
  263.                       BEGIN;
  264.  
  265.                         {$IFDEF DEBUG}
  266.                           WRITELN('Command --', LENGTH(line_to), '-', line_to);
  267.                         {$ENDIF}
  268.  
  269.                         line_to := COPY(line_to, 2, 255);
  270.                         execute_opr_command(@line_to);
  271.                         error_sw := FALSE;
  272.                       END;
  273.                   END
  274.                 ELSE
  275.                   BEGIN;
  276.  
  277.                     {$IFDEF DEBUG}
  278.                       WRITELN('Data-', LENGTH(work_scb^.str_m_data.str_data),
  279.                                      '-', work_scb^.str_m_data.str_data);
  280.                     {$ENDIF}
  281.  
  282.                     send_tnc_data(@work_scb^.str_m_data);
  283.                     send_flush;
  284.                   END;
  285.  
  286.                 del_c_string(active_tcb);
  287.  
  288.               END; (*----- End the handling of outbound data ----------------*)
  289.  
  290.             (*---------------------------------------------------------------*)
  291.             (* See if any inbound data.  If so, distribute that              *)
  292.             (*---------------------------------------------------------------*)
  293.  
  294.             i := send_pending(FALSE);
  295.  
  296.             IF conv_tcb = NIL THEN
  297.               GOTO leave_loop;
  298.  
  299.             IF active_tcb^.tcb_binary THEN
  300.               BEGIN;
  301.  
  302.                 IF active_tcb^.i_data.long_length <> 0 THEN
  303.                   BEGIN;
  304.                     add_c_long(conv_tcb, @active_tcb^.i_data);
  305.  
  306.                     active_tcb^.i_data.long_length := 0;
  307.                     active_tcb^.i_data.str_data    := '';
  308.  
  309.                     delay_to_add := 1;
  310.                   END
  311.                 ELSE
  312.                   delay_to_add := 5;
  313.  
  314.               END
  315.             ELSE
  316.               BEGIN;
  317.  
  318.                 IF read_tnc_data_pending THEN
  319.                   BEGIN;
  320.                     line_to := read_tnc_data_str;
  321.                     add_c_string(conv_tcb, @line_to, 1);
  322.                     delay_to_add := 1;
  323.                   END
  324.                 ELSE
  325.                   delay_to_add := 5;
  326.  
  327.               END;
  328.  
  329.             (*---------------------------------------------------------------*)
  330.             (* Switch away!                                                  *)
  331.             (*---------------------------------------------------------------*)
  332.  
  333.             IF modem_line THEN
  334.               task_switch
  335.             ELSE
  336.               FOR i := 1 TO delay_to_add DO
  337.                 task_switch;
  338.  
  339.           END; (*----- End talk loop ----------------------------------------*)
  340.  
  341. leave_loop:
  342.  
  343.         (*-------------------------------------------------------------------*)
  344.         (* Talk complete.  Remove us from list                               *)
  345.         (*-------------------------------------------------------------------*)
  346.  
  347.         tcb_opr_talk := FALSE;
  348.  
  349.       END;
  350.  
  351.   END;
  352.  
  353. END.
  354.  
  355.